package medium;
/*
915. 分割数组
 */
public class LeeCode915 {

  public static void main(String[] args) {
    int[]num = {5, 0, 3, 8, 6};
    System.out.println(new LeeCode915().partitionDisjoint(num));
  }

  public int partitionDisjoint(int[] nums) {

    int left = 1;
    int right = nums.length - 1;
    int leftNum = nums[0];
    int rightNum = nums[right];
    while (left <= right){
      if (leftNum <= rightNum){
        rightNum = Math.min(rightNum,nums[--right]);
      }else {
        leftNum = Math.max(leftNum,nums[left++]);
      }
    }
    int k = left;
    while (k < nums.length){
      if (nums[k] < leftNum){
        left = k + 1;
      }
      k++;
    }
    return left;
  }
}
